import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Class to represent Chris Hansen's famous have a seat over here attack.
 */
public class Stool  extends Actor
{
    Simon simon;
    Health health;
    retroWorld theWorld;
    
    int vSpeed, acceleration, halfImg;
    
    public Stool()
    {
        vSpeed = 0;
        acceleration = 1;
        halfImg = getImage().getHeight()/2;
    }

    /**
     * Act - do whatever the Stool wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (intersects(simon))
            health.takeDamage();
            
        setRotation( vSpeed);
        fall();
    }    
    
    public void addedToWorld(World world)
    {
        theWorld = (retroWorld)world;
        simon = theWorld.getSimon();
        health = theWorld.getHealth();      
    }
    
    /** Fall toward the ground
     * 
     */
    private void fall()
    {
        vSpeed = vSpeed + acceleration;
        
        //Remove Stool when it hits the ground
        for (int i = 0; i <= vSpeed; i++)
            if (theWorld.isGround(getX(), getY() + halfImg + i))
            {
                theWorld.removeObject(this);
                return;
            }
        
        setLocation (getX(), (getY() + vSpeed)); 
    }
}